package com.weetop.aklyscan.activity;

import static com.weetop.aklyscan.activity.OutRecordListActivity.ORDER_TYPE_MATTER_PP;
import static com.weetop.aklyscan.activity.OutRecordListActivity.ORDER_TYPE_ONLINE_PP;
import static com.weetop.aklyscan.activity.OutRecordListActivity.ORDER_TYPE_PRODUCT_SC;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.weetop.aklyscan.R;
import com.weetop.aklyscan.base.BaseActivity;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.bean.BaseList;
import com.weetop.aklyscan.bean.OutRecordListBean;
import com.weetop.aklyscan.bean.RecordBean;
import com.weetop.aklyscan.presenter.RecordPresent;
import com.weetop.aklyscan.view.RecordView;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OutPeiJianRecordActivity extends BaseActivity<RecordPresent> implements RecordView, CommonRecyclerAdapter.OnItemClickListener {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.txt_title)
    TextView txt_title;
    @BindView(R.id.tv_1)
    TextView tv_1;
    @BindView(R.id.tv_ck_time)
    TextView menu2;
    @BindView(R.id.tv_ck_num)
    TextView menu3;
    @BindView(R.id.tv_order_sn)
    TextView menu4;
    @BindView(R.id.tv_member_sn)
    TextView menu5;
    private CommonRecyclerAdapter<OutRecordListBean> adapter;
    private List<OutRecordListBean> list = new ArrayList<>();

    @Override
    protected RecordPresent createPresenter() {
        return new RecordPresent(this, this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_out_record_1);
        ButterKnife.bind(this);
        OutRecordListBean outRecordListBean = (OutRecordListBean) getIntent().getSerializableExtra("record_model");
        int order_type = getIntent().getIntExtra("order_type", ORDER_TYPE_MATTER_PP);
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new CommonRecyclerAdapter<OutRecordListBean>(mActivity, R.layout.item_record_1, list) {
            @Override
            public void onUpdate(BaseAdapterHelper helper, OutRecordListBean item, int position) {
                helper.setText(R.id.tv_xuhao, position + 1 + "");
                if (order_type == ORDER_TYPE_MATTER_PP) {
                    helper.setText(R.id.tv_sn_code, item.getMatter_code());
                    helper.setText(R.id.tv_model, item.getMatter_name());
                    helper.setText(R.id.tv_name, item.getCk_num());
                } else {
                    helper.setText(R.id.tv_sn_code, TextUtils.isEmpty(item.getCode()) ? item.getSerial_code() : item.getCode());
                    helper.setText(R.id.tv_model, item.getGoods_model());
                    helper.setText(R.id.tv_name, item.getGoods_name());
                }
                helper.setVisible(R.id.tv_xiang, order_type != ORDER_TYPE_PRODUCT_SC);
                helper.setVisible(R.id.tv_huojia, order_type != ORDER_TYPE_PRODUCT_SC);
                helper.setText(R.id.tv_xiang, item.getTransit_code());
                helper.setText(R.id.tv_huojia, item.getWarehouse_coordinates());
            }
        };
//        txt_title.setText("出库记录详情");
        adapter.setOnItemClickListener(this);
        recyclerView.setAdapter(adapter);
//        adapter.add(outRecordListBean);
        if (order_type == ORDER_TYPE_MATTER_PP) {
            tv_1.setText("配件编号");
            menu2.setText("配件名称");
            menu3.setText("数量");
            mPresenter.Out16(outRecordListBean.getOrder_sn(), outRecordListBean.getCk_time());
        } else if (order_type == ORDER_TYPE_ONLINE_PP) {
            mPresenter.Out14(outRecordListBean.getOrder_sn(), outRecordListBean.getCk_time());
        } else if (order_type == ORDER_TYPE_PRODUCT_SC) {
            menu4.setVisibility(View.GONE);
            menu5.setVisibility(View.GONE);
            mPresenter.Into30(outRecordListBean.getOrder_sn(), outRecordListBean.getUpdate_time());
        } else {
            mPresenter.Out12(outRecordListBean.getOrder_sn(), outRecordListBean.getCk_time());
        }
    }

    @Override
    public void getOut09Success(BaseModel<BaseList<OutRecordListBean>> o) {
        List<OutRecordListBean> listBeans = o.getData().getList_data();
        list.clear();
        adapter.clear();
        list.addAll(listBeans);
        adapter.addAll(listBeans);
//        totalNumView.setText(o.getData().getCount()+"");
    }

    @Override
    public void getInto30Success(BaseModel<List<OutRecordListBean>> o) {
        List<OutRecordListBean> listBeans = o.getData();
        list.clear();
        adapter.clear();
        list.addAll(listBeans);
        adapter.addAll(listBeans);
    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int i) {

    }
}
